//
//  NormalArrowCell.m
//  s.
//
//  Created by fanshijian on 2022/9/5.
//  Copyright © 2022 J. All rights reserved.
//

#import "NormalArrowCell.h"
#import "NormalArrowModel.h"

@interface NormalArrowCell ()

@property (weak, nonatomic) UILabel *titleLab;
@property (weak, nonatomic) UILabel *valueLab;
@property (weak, nonatomic) UIImageView *icon;
@property (weak, nonatomic) UIImageView *arrowView;

@end


@implementation NormalArrowCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//        self.backgroundColor = [UIColor clearColor];
//        self.contentView.backgroundColor = [UIColor whiteColor];
//        self.contentView.layer.cornerRadius = frame.size.height / 2;
//        self.contentView.layer.shadowColor = [UIColor blackColor].CGColor;
//        self.contentView.layer.shadowOffset = CGSizeMake(5, 8);
//        self.contentView.layer.shadowRadius = frame.size.height / 2;
//        self.contentView.layer.shadowOpacity =  0.25;
    }
    return self;
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        UILabel *obj = [UILabel new];
        [self addSubview:_titleLab = obj];
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeL(self.icon.mas_right).offset(10);
            kMakeCenterYV(0);
        }];
        obj.font = U_bfont(16);
        obj.textColor = KLColor(@"#333333");
    }
    return _titleLab;
}

- (UILabel *)valueLab {
    if (!_valueLab) {
        UILabel *obj = [UILabel new];
        [self addSubview:_valueLab = obj];
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeR(self.arrowView.mas_left).offset(-8);
            make.left.greaterThanOrEqualTo(self.titleLab.mas_right).offset(10);
            kMakeCenterYV(0);
        }];
        obj.font = U_font(12);
        obj.textColor = KLColor(@"#B5B5B5");
        obj.textAlignment = NSTextAlignmentRight;
        obj.numberOfLines = 0;
    }
    return _valueLab;
}

- (UIImageView *)arrowView {
    if (!_arrowView) {
        UIImageView *obj = [UIImageView new];
        [self.contentView addSubview:_arrowView = obj];
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeWHV(18, 18);
            kMakeRV(-17);
            kMakeCenterYV(0);
        }];
        obj.image = U_imageNamed(@"icon_sport_month_arrow");
        obj.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _arrowView;
}
- (UIImageView *)icon {
    if (!_icon) {
        UIImageView *obj = [UIImageView new];
        [self.contentView addSubview:_icon = obj];
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeWHV(40, 40);
            kMakeLV(15);
            kMakeCenterYV(0);
        }];
    }
    return _icon;
}
- (void)setModel:(NormalArrowModel *)model {
    if (self.model != model || model.modified) {
        [super setModel:model];
        self.klBottomLine.hidden = NO;
        if (model.icon) {
            self.icon.image = U_imageNamed(model.icon);
        }
        if (model.tf) {
            self.titleLab.font = model.tf;
        }else {
            self.titleLab.font = U_font(14);
        }
        self.titleLab.textAlignment = model.textAlignment;
        if (model.tColor) {
            self.titleLab.textColor = KLColor(model.tColor);
        }else {
            self.titleLab.textColor = KLColor(@"#000000");
        }
        if (model.titleMakerBlock) {
            [self.titleLab mas_remakeConstraints:model.titleMakerBlock];
        }
        if (model.title) {
            if ([model.title isKindOfClass:NSAttributedString.class]) {
                self.titleLab.attributedText = model.title;
            }else {
                self.titleLab.text = model.title;
            }
        }else {
            self.titleLab.text = @"";
        }
        
        if (model.color) {
            self.backgroundColor = KLColor(model.color);
        }else {
            self.backgroundColor = [UIColor clearColor];
        }
        
        if (model.right_tf) {
            self.valueLab.font = model.right_tf;
        }else {
            self.valueLab.font = U_font(14);
        }
        self.valueLab.textAlignment = model.right_textAlignment;
        if (model.right_tColor) {
            self.valueLab.textColor = KLColor(model.right_tColor);
        }else {
            self.valueLab.textColor = KLColor(@"#000000");
        }
        if (model.right_tCor) {
            self.valueLab.textColor = model.right_tCor;
        }
//        else {
//            self.valueLab.textColor = kPlaceHolderColor;
//        }
        
        if (model.desc) {
            if ([model.desc isKindOfClass:NSAttributedString.class]) {
                self.valueLab.attributedText = model.desc;
            }else {
                self.valueLab.text = model.desc;
            }
        }else {
            self.valueLab.text = nil;
        }
        if (model.value) {
            if ([model.value isKindOfClass:NSAttributedString.class]) {
                self.valueLab.attributedText = model.value;
            }else {
                self.valueLab.text = model.value;
            }
        }
        if (model.banInteraction) {
            self.arrowView.hidden = YES;
        }else {
            self.arrowView.hidden = model.hiddenArrow;
        }
        
        if (self.arrowView.hidden) {
            [self.valueLab mas_remakeConstraints:^(MASConstraintMaker *make) {
                kMakeRV(-16);
                make.left.greaterThanOrEqualTo(self.titleLab.mas_right).offset(10);
                kMakeCenterYV(0);
            }];
        } else {
            [self.valueLab mas_remakeConstraints:^(MASConstraintMaker *make) {
                kMakeR(self.arrowView.mas_left).offset(-8);
                make.left.greaterThanOrEqualTo(self.titleLab.mas_right).offset(10);
                kMakeCenterYV(0);
            }];
        }
        
        self.klBottomLine.hidden = model.hiddenLine;
        
        self.userInteractionEnabled = !model.banInteraction;
        
    }
}

@end
